package com.notary.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.notary.entity.vo.JsonResult;
import  com.notary.service.NotaryBusinessService;
import com.notary.entity.NotaryBusiness;

/**
* <p>
* 公证业务基本信息 前端控制器
* </p>
* @author xujun
* @since 2020-07-28
*/


@Api(tags = "公证业务基本信息控制器")
@RequestMapping("/notaryBusiness")
@RestController
public class NotaryBusinessController{


    NotaryBusinessService notaryBusinessService;

    @Autowired
    public  NotaryBusinessController(NotaryBusinessService notaryBusinessService){
        this.notaryBusinessService = notaryBusinessService;
    }

    /**
    * <p>
        * 根据条件查询全部记录（并翻页）
        * </p>
    */

    @ApiOperation(value = "列表查询")
    @PostMapping("/list")
    public JsonResult<IPage<NotaryBusiness>> list(int pageNum, int pageSize) {
        Page<NotaryBusiness> page = new Page<NotaryBusiness>(pageNum,pageSize);
        IPage<NotaryBusiness> iPage = notaryBusinessService.page(page,new QueryWrapper<>());
        return JsonResult.success(iPage);
    }


    /**
        *<P>
        * 根据ID查找返回单个对象
        *</P>
    */
    @ApiOperation(value = "根据id查询")
    @GetMapping("/find/{id}")
    public JsonResult<NotaryBusiness> getById(@PathVariable("id") Integer id) {
         return JsonResult.success(notaryBusinessService.getById(id));
    }


    /**
        *<p>
        * 保存对象-如果对象存在则修改原数据，否则插入一条新数据
        *</p>
    */
    @ApiOperation(value = "保存对象")
    @GetMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody NotaryBusiness notaryBusiness) {
        return JsonResult.success(notaryBusinessService.saveOrUpdate(notaryBusiness));
    }


    /**
        *<p>
        * 根据 id删除记录-逻辑删除
        *</p>
    */
    @ApiOperation(value = "删除")
    @GetMapping("/remove/{id}")
    public JsonResult removeById(@PathVariable("id") Integer id) {
        return JsonResult.success(notaryBusinessService.removeById(id));
    }


}

                       